package com.nowcoder.community.util;
import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;
/**
 * @author 夏智力
 * @FileName HostHolder
 * @date 2021/6/3 16:20
 * @Software: IntelliJ IDEA
 */


/**
 * 持有用户信息，用于代替session对象的
 */
@Component
public class HostHolder {

    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear() {
        users.remove();
    }
}
